load TagBlock,EventHeaders

if #msg="Media"
  Gosub TagBlock,"OBJE","Media"
  ShowAll SOUR "Media"
  hideexcess
  
else if #msg="Sources"
  if @count.SOUR+@count.NOTE>0
    newline
    #elabel=local(@tag)
    if @DATE!=""
      #elabel&=" ("&@DATE.user&")"
    endif
    cell static,#elabel
    set width -1 offset 3
    ShowAll NOTE
    ShowAll SOUR
  endif
  hideexcess
  
else
  if #oneTable="yes"
    newline -1
  else
    newline
  endif

  ! header on first event
  ifNdef #first
    #first="yes"
  endif
  if #first="yes"
    if #oneTable="yes"
      GoSub EventHeaders
    else
      newline 10
      cell static,local("Attribute")
      set tabwidth 1 alignment center border square
      cellBackground "Table Cell Background"
      set borderColor "Table Cell Background" borderWidth 1

      cell static,local("Description")
      set tabwidth 1 alignment center border square
      cellBackground "Table Cell Background"
      set borderColor "Table Cell Background" borderWidth 1

      newline 1
      #first="no"
    endif
  endif
  
  ! event name, check box, and date
  if @tag="FACT"
    #eName=@TYPE
    if #eName=""
      #eName=local(@tag)
      cell static,#eName
    else
      cell expression,@TYPE
      localize true
    endif
  else
    cell static,local(@tag)
  endif
  if #oneTable="yes"
    #tw=2 
  else
    #tw=1
  endif
  set tabwidth #tw alignment center border square
  cellBackground "Table Cell Background"
  set borderColor "Table Cell Background" borderWidth 1
  
  if #oneTable="yes"
    hskip 0
    #dpos=#hpos$
    tab 1
    hskip #cellSkip
  endif

  ! edit contents of the attribute
  if @tag="RESI"
    cell Expression @ADDR
    set AppendedExpression contents.trunc border square cellbackground "Table Cell Background"
    set borderColor "Table Cell Background" borderWidth 1
  else
    cell EditValue
  endif
  set tabwidth #tw
  
  if #oneTable="yes"
    HMoveTo #dpos
    Show DATE Event
    tab 2
    hskip #cellSkip
  endif

  ! rest in a child window
  cell StructuresLink,AttrDetails,@tag
  set border no width -1
  if more
    set image "details_here"
  else
    set image "details"
  endif
  LinkAll all

  #tagKey=@tag&" details"
  help local("Click to edit")&": "&local(#tagKey)
  
  newline 1
endif
